/****************************************************
          File Name:array_stack.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 09 Feb 2015 10:31:55 AM CST
*****************************************************/

#ifndef array_stack_h_
#define array_stack_h_

#include <stdbool.h>
#include <stdio.h>

#define MAX 5 // stack size
typedef struct STACK
{
    int data[MAX];
    int top;
} Stack;

void InitStack(Stack *s)
{
    s->top = 0;
}

bool isFull(Stack *s)
{
    return s->top == MAX ? true : false;
}

bool isEmpty(Stack *s)
{
    return s->top == 0 ? true : false;
}

bool Push(Stack *s, int *element)
{
    if(isFull(s)) return false;

    s->data[s->top] = *element;
    s->top++;

    return true;
}

bool Pop(Stack *s, int *element)
{
    if(isEmpty(s)) return false;

    s->top--;
    *element = s->data[s->top];

    return true;
}

int StackLength(Stack *s)
{
    return s->top;
}

#endif
